import { invoke } from "@tauri-apps/api/core";
import { defineStore } from "pinia";
import { useUserStore } from "./user";

export const useMessageStore = defineStore('message', () => {

    const init = async () => {
        const userStore = useUserStore();
        const userId = userStore.getId;
        if (userId != undefined) {
            await invoke('start_mqtt', {userId: userId});
        }
        console.log("start_mqtt---->");
    }

    const publish = async (topic: string) => {
        await invoke('publish', {
            "topic": topic
        });
    }

    return {
        init, publish
    }
})